# $Id$
# Maintainer:  Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Dave Reisner <dreisner@archlinux.org>
# Contributor: Thomas Bächler <thomas@archlinux.org>

pkgname=mkinitcpio-busybox
pkgver=1.26.1
pkgrel=1
pkgdesc='Base initramfs tools'
arch=(i686 x86_64)
url="http://www.busybox.net/"
license=(GPL)
depends_x86_64=(glibc)
options=(!buildflags)
source=(https://busybox.net/downloads/busybox-$pkgver.tar.bz2
        config)
sha256sums=('0fbbe487fa35cc3258749cf79c259578c1a221013cc4fb60d6a3542590f781f2'
            '4cf727c87f97b2c72e6a76fa710eaa84104fdc51d0ec232eba120c9fa17e1ab3')

prepare() {
  cd "busybox-$pkgver"

  local safeflags="-march=${CARCH/_/-} -mtune=generic -Os -pipe -fno-strict-aliasing"

  sed 's|^\(CONFIG_EXTRA_CFLAGS\)=.*|\1="'"$safeflags"'"|' "$srcdir/config" >.config

  # workaround for FS#54240
  if [[ $CARCH == 'i686' ]]; then
    echo 'CONFIG_STATIC=y' >> .config
  fi
}

build() {
  make -C "busybox-$pkgver"
}

package() {
  install -Dm755 "$srcdir/busybox-$pkgver/busybox" "$pkgdir/usr/lib/initcpio/busybox"
}
